package de.klingbeil.hhc.client.model;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;

import de.klingbeil.hhc.client.ItemProxy;

public class ItemModelData extends BaseModelData {
	public static final String ID = "id";
	public static final String DESCRIPTION = "description";
	private static final long serialVersionUID = 1L;

	public ItemModelData() {

	}

	public ItemModelData(Long id) {
		set(ID, id);
	}

	public Long getId() {
		return get(ID);
	}

	public static ItemModelData from(ItemProxy itemProxy) {
		assertNotNull(itemProxy, "itemProxy");
		ItemModelData result = new ItemModelData(itemProxy.getId());
		result.setDescription(itemProxy.getDescription());
		return result;
	}

	public static List<ItemModelData> from(List<ItemProxy> items) {
		assertNotNull(items, "itemProxy");
		List<ItemModelData> result = new ArrayList<ItemModelData>(items.size());
		for (ItemProxy item : items) {
			result.add(ItemModelData.from(item));
		}
		return result;
	}

	private static void assertNotNull(Object obj, String msg) {
		if (obj == null) {
			throw new IllegalArgumentException(msg);
		}
	}

	public void setDescription(String description) {
		set(DESCRIPTION, description);
	}

	public String getDescription() {
		return get(DESCRIPTION);
	}
}
